<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @package			RemaInventoryManagement
 * @subpackage	    PT. RemasysIndo
 * @category		Customized Version
 * @author			Jalu Ahmad Pambudi
 * @mail            j.a.pambudi@gmail.com
 * @copyright		
 * @license			http://remasysindo.com/
 * @link			http://remasysindo.com/remainv/
 */


class Admin_dailytrans extends MY_Controller {
	var  $tanggal;
    function __construct() {
	  parent::__construct();
	  $cek_admin = $this->session->userdata('cek_admin');
	  if (!$cek_admin) redirect("admin");
	  $this->session->unset_userdata('tanggal');
	  
	  $this->mDailyTrans = new M_dailyTrans();
    }
	
	function index() {
	  $data['title'] = 'Menu Daily Transactions';
	  $data['tanggal'] =$this->session->userdata('tanggal');
	  $data['isi'] = 'main';
	  $this->load->view('template_admin', $data);
	}
	
	function todayPrice() {
	  /*$sekCode = $this->input->post('sekCode');
	  $stockCode = $this->input->post('stockCode');
	  ($sekCode == 'Sekuritas :' || $sekCode == 'Sekuritas : ') ? $sekCode=NULL : $sekCode;
	  ($stockCode == 'StockName: ' || $stockCode == 'StockName:') ? $stockCode=NULL : $stockCode;
	  $data['stockCode'] = $stockCode;
	  $data['sekCode'] = $sekCode;
	  $data['stockList'] = $this->mDailyTrans->getStockList();
	  $data['sekList'] = $this->mDailyTrans->getSekList();
	  */
	  $data['title'] = "Update Today's Price";
	  #$data['tanggal'] = date('Y-m-d');
	  #die($this->input->post('dateForMe'));
	  if (! $this->session->userdata('tanggal')) {
		$datePost = $this->input->post('dateForMe');
		$this->session->set_userdata('tanggal', $datePost);
		$data['tanggal'] = $datePost ;
	  } else { 
		$data['tanggal'] = $this->session->userdata('tanggal');
	  }
	  #die($data['tanggal']);
	  $data['gridData'] = $this->mDailyTrans->getData($data['tanggal']);
	  $data['url'] = site_url('admin_dailytrans/setupPriceTable');
	  
	  $data['isi'] = 'form' ;
	  $this->load->view('template_admin', $data);
	}
	
	function setupPriceTable() {
	  if (empty($tanggal) || $tanggal='0000-00-00') {
			$tanggal = $ci->session->userdata('tanggal');
		}
	  #$tanggal= empty($this->tanggal) ? $this->input->post('tanggal') : $this->session->userdata('tanggal');
	  
	  #print $tanggal." controller";
	  #$this->mDailyTrans->setupPriceTable->tanggal= $tanggal;
	  $mySetup = $this->mDailyTrans->setupPriceTable($tanggal);
	  (! $mySetup) ? $this->todayPrice  :  redirect('admin_dailytrans');
	  // $data['title'] = "Update Today's Price";
	  // $data['tanggal'] = $tanggal ;
	  // $data['url'] = site_url('admin_dailytrans/setupPriceTable');
	  // $data['gridData'] = $this->mDailyTrans->getData($tanggal);
	  // $data['isi'] = 'form' ;
	  // $this->load->view('template_admin', $data);
	}
	
	function updatePrice() {
	  #$updateData =array('value'=>$_POST['value'], 'tanggal'=>$this->session->userdata('tanggal'));
	  $tanggal = $this->session->userdata('tanggal');
	  $updateData = $_POST['value'];
	  $id = $_POST['row_id'];
	  
	  $isExists = $this->mDailyTrans->getByDate($tanggal);
	  if ($isExists==false) { $this->mDailyTrans->setupPriceTable($tanggal); }
	  
	  $returnMe = $this->mDailyTrans->updatePrice($updateData,$id,$tanggal);
	  
	  print $updateData;
	  return $updateData;
	}
}

?>